<?php
/**********************
**index.php
**Date Created: 4/13/2009
**Copyright 2009 Tomorrow Tech Industries
**Contact: RPITomorrowTech@gmail.com
**********************/

require_once("private/arrays.inc");
require_once("private/login.inc");

/**
 * Determines whether or not to display the login
 * form or to show the user that he is logged in
 * based on if the session variables are set.
 */
function displayLogin()
{
	echo"
		<h1>Login</h1>
		<form name=\"LogIn\" action=\"main.php\" method=\"post\">
		<table align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
		<tr>
			<td>Username:</td><td><input type=\"text\" name=\"user\" maxlength=\"24\">
			</td>
		</tr>
		<tr>
			<td>
				Password:
			</td>
			<td>
				<input type=\"password\" name=\"pass\" maxlength=\"24\">
			</td>
		</tr>
		<tr>
			<td colspan=\"2\" align=\"left\">
				<input type=\"checkbox\" disabled=\"disabled\" name=\"remember\" />
				<font size=\"2\" color=\"#666666\">
					Remember me next time
				</font>
			</td>
		</tr>
		<tr>
			<td colspan=\"2\" align=\"right\">
				<input type=\"submit\" name=\"sublogin\" value=\"Login\" />
			</td>
		</tr>
		";
	/*
	echo "
		<tr>
			<td colspan=\"2\" align=\"left\">
				<a href=\"register.php\">Join</a>
			</td>
		</tr>
		";
	*/
	echo "
		</table>
		</form>
		<script type=\"text/javascript\" language=\"JavaScript\">
		document.forms['LogIn'].elements['user'].focus();
		</script>
		";
}

function displayPage()
{
	echo "
		<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
		<html xmlns=\"http://www.w3.org/1999/xhtml\">
		<head>
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
		<title>Sign In to Intellimation</title>
		<style type=\"text/css\">
		<!--
		body {
			margin-right: 775px;
		}
		.style1 {font-size: 9px}
		-->
		</style></head>

		<body>
		<h1>Intellimation [Sign In]</h1><br />
		";

	if( isset($_GET[QUERY_LOGIN_DENY]) )
	{
		$denyReason = $_GET[QUERY_LOGIN_DENY];
		echo "Your login was denied: " . $denyReason . "<BR>";
	}

  	displayLogin();
	echo "
		<br />
		<br />
		<br />
		";
	/*
	echo "
		<br />
		<br />
		<br />
		  <div align=\"right\"><a href=\"main.php\">Sign In</a> </div>
		<br />
		<br />
		<br />
		";		
	*/

	bottom();
}

if( checkLogin() )
{
	$URL = "main.php";
	header("Location: $URL");
}
else
{
	displayPage();
}

?>